﻿using System;
using System.IO;
using System.Windows.Forms;

namespace ZLSoft.ZLDocEditorEvents.Comm
{
    internal class Func
    {
        static object objLock=new object();
        #region 模仿Oracle Nvl 函数

        /// <summary>
        /// 模仿Oracle的Nvl函数，当某个值为空是赋默认值
        /// </summary>
        /// <param name="strValue">需要判断的值</param>
        /// <param name="defaultValue">默认值</param>
        /// <returns></returns>
        internal static string Nvl(object strValue, string defaultValue = "")
        {
            //功能：相当于Oracle的NVL，将Null值改成另外一个预设值
            if (strValue == null)
            {
                return defaultValue;
            }
            else if (string.IsNullOrEmpty(strValue.ToString()))
            {
                return defaultValue;
            }
            else
            {
                return strValue.ToString();
            }
        }

        #endregion

        ///<summary>
        ///向系统的交易日志中写一条新的日志记录。
        ///</summary>
        ///<param name="log">日志的内容。</param>
        public static void WriteBusinessLog(string log)
        {
            try
            {
                if (Init.SaveLog)
                {
                   
                    string strFileName = Init.AssemblyDirectory + "\\VTE_" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
                    lock (objLock)
                    {
                        StreamWriter sw = new StreamWriter(strFileName, true);
                        sw.WriteLine("\n\n<<*************************************************************************************>>\n\n");
                        sw.WriteLine(log);
                        sw.Close();
                    }
                }
            }
            catch (Exception se)
            {
                MessageBox.Show(se.Message, "VTE卡控平台", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
